package com.huihe.storage.repository.Impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huihe.storage.entity.SysConfig;
import com.huihe.storage.mapper.SysConfigMapper;
import com.huihe.storage.repository.SysConfigRepository;
import org.springframework.stereotype.Service;

/**
 * 配置的 Repository 层
 */
@Service
public class SysConfigRepositoryImpl extends ServiceImpl<SysConfigMapper, SysConfig> implements SysConfigRepository {

    /**
     * 根据键查找配置信息
     * @param key 键
     * @return 配置信息
     */
    @Override
    public SysConfig findByKey(String key) {
        LambdaQueryWrapper<SysConfig> wrapper = new LambdaQueryWrapper<>();
        //sql: where key == "" and del_flag == "0"
        wrapper.eq(StrUtil.isNotBlank(key),SysConfig::getConfigKey,key);
        return getBaseMapper().selectOne(wrapper);
    }
}
